package com.julang.check.translate.common;

import java.util.HashMap;
import java.util.Map;
/**
 * @author 赵自强
 * */
public abstract class AbstractOnlineTranslator implements Translator {
    /**语言映射，由子类完成*/
    protected Map<LANG, String> langMap = new HashMap<>();

    @Override
    final public String trans(LANG from, LANG targ, String query) throws Exception {
        String response = "";
        try {
            response = getResponse(from, targ, query);
            String result = parseString(response);
            return result;
        } catch (Exception e) {
            return response;
        }
    }
    /**
     * 获取响应的数据
     * @param from
     * @param targ
     * @param query
     * @return String
     * @throws Exception
     */
    abstract protected String getResponse(LANG from, LANG targ, String query) throws Exception;
    /**
     * 解析获取的字符串
     * @param jsonString
     * @return String
     */
    abstract protected String parseString(String jsonString);
}
